home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Source / Property Editors / dblogdlg.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  3KB  |  125 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Visual Component Library         }
  5. {                                                       }
  6. {       Copyright (c) 1995,99 Inprise Corporation       }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit DBLogDlg;
  11.  
  12. {$P+,H+,X+}
  13.  
  14. interface
  15.  
  16. uses SysUtils, Windows, Messages, Classes, Graphics, Controls,
  17.   Forms, StdCtrls, ExtCtrls;
  18.  
  19. type
  20.   TLoginDialog = class(TForm)
  21.     Panel: TPanel;
  22.     Bevel: TBevel;
  23.     DatabaseName: TLabel;
  24.     OKButton: TButton;
  25.     CancelButton: TButton;
  26.     Panel1: TPanel;
  27.     Label1: TLabel;
  28.     Label2: TLabel;
  29.     Label3: TLabel;
  30.     Password: TEdit;
  31.     UserName: TEdit;
  32.     procedure FormShow(Sender: TObject);
  33.   end;
  34.  
  35. function LoginDialog(const ADatabaseName: string;
  36.   var AUserName, APassword: string): Boolean;
  37.  
  38. function LoginDialogEx(const ADatabaseName: string;
  39.   var AUserName, APassword: string; NameReadOnly: Boolean): Boolean;
  40.  
  41. function RemoteLoginDialog(var AUserName, APassword: string): Boolean;
  42.  
  43. implementation
  44.  
  45. {$R *.DFM}
  46.  
  47. uses DBConsts;
  48.  
  49. function LoginDialog(const ADatabaseName: string;
  50.   var AUserName, APassword: string): Boolean;
  51. begin
  52.   with TLoginDialog.Create(Application) do
  53.   try
  54.     DatabaseName.Caption := ADatabaseName;
  55.     UserName.Text := AUserName;
  56.     Result := False;
  57.     if AUserName = '' then ActiveControl := UserName;
  58.     if ShowModal = mrOk then
  59.     begin
  60.       AUserName := UserName.Text;
  61.       APassword := Password.Text;
  62.       Result := True;
  63.     end;
  64.   finally
  65.     Free;
  66.   end;
  67. end;
  68.  
  69. function LoginDialogEx(const ADatabaseName: string;
  70.   var AUserName, APassword: string; NameReadOnly: Boolean): Boolean;
  71. begin
  72.   with TLoginDialog.Create(Application) do
  73.   try
  74.     DatabaseName.Caption := ADatabaseName;
  75.     UserName.Text := AUserName;
  76.     Result := False;
  77.     if NameReadOnly then
  78.       UserName.Enabled := False
  79.     else
  80.       if AUserName = '' then ActiveControl := UserName;
  81.     if ShowModal = mrOk then
  82.     begin
  83.       AUserName := UserName.Text;
  84.       APassword := Password.Text;
  85.       Result := True;
  86.     end;
  87.   finally
  88.     Free;
  89.   end;
  90. end;
  91.  
  92. function RemoteLoginDialog(var AUserName, APassword: string): Boolean;
  93. begin
  94.   with TLoginDialog.Create(Application) do
  95.   try
  96.     Caption := SRemoteLogin;
  97.     Bevel.Visible := False;
  98.     DatabaseName.Visible := False;
  99.     Label3.Visible := False;
  100.     Panel.Height := Panel.Height - Bevel.Top;
  101.     OKButton.Top := OKButton.Top - Bevel.Top;
  102.     CancelButton.Top := CancelButton.Top - Bevel.Top;
  103.     Height := Height - Bevel.Top;
  104.     UserName.Text := AUserName;
  105.     Result := False;
  106.     if AUserName = '' then ActiveControl := UserName;
  107.     if ShowModal = mrOk then
  108.     begin
  109.       AUserName := UserName.Text;
  110.       APassword := Password.Text;
  111.       Result := True;
  112.     end;
  113.   finally
  114.     Free;
  115.   end;
  116. end;
  117.  
  118. procedure TLoginDialog.FormShow(Sender: TObject);
  119. begin
  120.   if (DatabaseName.Width + DatabaseName.Left) >= Panel.ClientWidth then
  121.     DatabaseName.Width := (Panel.ClientWidth - DatabaseName.Left) - 5;
  122. end;
  123.  
  124. end.
  125.